package com.fdb.efp.nls.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.nls.service.domain.BdYxapplyTemp;
import com.fdb.efp.nls.service.facade.BdYxapplyTempService;
import com.fdb.efp.nls.service.vo.BdYxapplyTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fdb.basic.framework.core.base.FrameworkService;


import com.fdb.efp.nls.service.dao.BdYxapplyTempDao;

/**
 * Service Impl: 实时进件-用信申请信息临时表服务实现
 * 
 * @author ligm
 * @date 2019-05-06
 */
@Service("bdYxapplyTempService")
public class BdYxapplyTempServiceImpl implements BdYxapplyTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdYxapplyTempServiceImpl.class);

	@Autowired
	private BdYxapplyTempDao bdYxapplyTempDao;

	/**
	 * 新增数据
	 * 
	 * @param inBdYxapplyTempVo
	 * @return
	 */
	public int insertBdYxapplyTemp(BdYxapplyTempVO inBdYxapplyTempVo) {
		logger.debug("当前新增数据为:" + inBdYxapplyTempVo.toString());
		int num = 0;
		try {
			BdYxapplyTemp bdYxapplyTemp = new BdYxapplyTemp();
			beanCopy(inBdYxapplyTempVo, bdYxapplyTemp);
			num = bdYxapplyTempDao.insertBdYxapplyTemp(bdYxapplyTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 根据主键删除信息
	 * 
	 * @param inBdYxapplyTempVo
	 * @return
	 */
	public int deleteByPk(BdYxapplyTempVO inBdYxapplyTempVo) {
		logger.debug("当前删除数据条件为:" + inBdYxapplyTempVo);
		int num = 0;
		try {
			BdYxapplyTemp bdYxapplyTemp = new BdYxapplyTemp();
			beanCopy(inBdYxapplyTempVo, bdYxapplyTemp);
			num = bdYxapplyTempDao.deleteByPk(bdYxapplyTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdYxapplyTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键更新信息
	 * 
	 * @param inBdYxapplyTempVo
	 * @return
	 */
	public int updateByPk(BdYxapplyTempVO inBdYxapplyTempVo) {
		logger.debug("当前修改数据为:" + inBdYxapplyTempVo.toString());
		int num = 0;
		try {
			BdYxapplyTemp bdYxapplyTemp = new BdYxapplyTemp();
			beanCopy(inBdYxapplyTempVo, bdYxapplyTemp);
			num = bdYxapplyTempDao.updateByPk(bdYxapplyTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdYxapplyTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 根据主键查询详情
	 * 
	 * @param bdYxapplyTemp
	 * @return
	 */
	public BdYxapplyTempVO queryByPk(BdYxapplyTempVO inBdYxapplyTempVo) {

		logger.debug("当前查询参数信息为:" + inBdYxapplyTempVo);
		try {
			BdYxapplyTemp queryBdYxapplyTemp = new BdYxapplyTemp();
			beanCopy(inBdYxapplyTempVo, queryBdYxapplyTemp);
			BdYxapplyTemp queryRslBdYxapplyTemp = bdYxapplyTempDao.queryByPk(queryBdYxapplyTemp);
			if (Objects.nonNull(queryRslBdYxapplyTemp)) {
				BdYxapplyTempVO outBdYxapplyTempVo = beanCopy(queryRslBdYxapplyTemp, new BdYxapplyTempVO());
				logger.debug("当前查询结果为:" + outBdYxapplyTempVo.toString());
				return outBdYxapplyTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 一级数据权限
	 * 
	 * @param bdYxapplyTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BdYxapplyTempVO> queryAllByLevelOne(BdYxapplyTempVO bdYxapplyTempVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<BdYxapplyTempVO> list = null;
		try {
			List<BdYxapplyTemp> bdYxapplyTemps = bdYxapplyTempDao.queryAllByLevelOneByPage(bdYxapplyTempVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:" + bdYxapplyTemps.size());
			pageSet(bdYxapplyTemps, bdYxapplyTempVo);
			list = (List<BdYxapplyTempVO>) beansCopy(bdYxapplyTemps, BdYxapplyTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 二级数据权限
	 * 
	 * @param bdYxapplyTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BdYxapplyTempVO> queryAllByLevelTwo(BdYxapplyTempVO bdYxapplyTempVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<BdYxapplyTemp> bdYxapplyTemps = bdYxapplyTempDao.queryAllByLevelTwoByPage(bdYxapplyTempVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:" + bdYxapplyTemps.size());
		List<BdYxapplyTempVO> list = null;
		try {
			pageSet(bdYxapplyTemps, bdYxapplyTempVo);
			list = (List<BdYxapplyTempVO>) beansCopy(bdYxapplyTemps, BdYxapplyTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 三级数据权限
	 * 
	 * @param bdYxapplyTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BdYxapplyTempVO> queryAllByLevelThree(BdYxapplyTempVO bdYxapplyTempVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<BdYxapplyTemp> bdYxapplyTemps = bdYxapplyTempDao.queryAllByLevelThreeByPage(bdYxapplyTempVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:" + bdYxapplyTemps.size());
		List<BdYxapplyTempVO> list = null;
		try {
			pageSet(bdYxapplyTemps, bdYxapplyTempVo);
			list = (List<BdYxapplyTempVO>) beansCopy(bdYxapplyTemps, BdYxapplyTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 四级数据权限
	 * 
	 * @param bdYxapplyTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BdYxapplyTempVO> queryAllByLevelFour(BdYxapplyTempVO bdYxapplyTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<BdYxapplyTemp> bdYxapplyTemps = bdYxapplyTempDao.queryAllByLevelFourByPage(bdYxapplyTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + bdYxapplyTemps.size());
		List<BdYxapplyTempVO> list = null;
		try {
			pageSet(bdYxapplyTemps, bdYxapplyTempVo);
			list = (List<BdYxapplyTempVO>) beansCopy(bdYxapplyTemps, BdYxapplyTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 五级数据权限
	 * 
	 * @param bdYxapplyTemp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BdYxapplyTempVO> queryAllByLevelFive(BdYxapplyTempVO bdYxapplyTempVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<BdYxapplyTemp> bdYxapplyTemps = bdYxapplyTempDao.queryAllByLevelFiveByPage(bdYxapplyTempVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:" + bdYxapplyTemps.size());
		List<BdYxapplyTempVO> list = null;
		try {
			pageSet(bdYxapplyTemps, bdYxapplyTempVo);
			list = (List<BdYxapplyTempVO>) beansCopy(bdYxapplyTemps, BdYxapplyTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 
	 * 分页查询【用信申请临时表】 <br>
	 * 0.1:weijj:2019年5月7日 下午2:37:18:新增 <br>
	 * 
	 * @author weijj
	 * @since 2019年5月7日 下午2:37:18
	 * @date 2019年5月7日 下午2:37:18
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BdYxapplyTempVO> queryByPage(BdYxapplyTempVO bdYxapplyTempVO) {
		// TODO Auto-generated method stub
		String msg1 = "分页用信申请临时表表";
		logger.debug(msg1, "message {}");
		List<BdYxapplyTempVO> list = null;
		try {
			List<BdYxapplyTemp> BdYxapplyTemps = bdYxapplyTempDao.queryByPage(bdYxapplyTempVO);
			list = (List<BdYxapplyTempVO>) beansCopy(BdYxapplyTemps, BdYxapplyTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【用信申请临时表】数据量 <br>
	 * 0.1:weijj:2019年5月7日 下午2:37:18:新增 <br>
	 * 
	 * @author weijj
	 * @since 2019年5月7日 下午2:37:18
	 * @date 2019年5月7日 下午2:37:18
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		// TODO Auto-generated method stub
		String msg1 = "查询【用信申请临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = bdYxapplyTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【用信申请临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
